import window from '@ohos.window';
import utils from '../common/core/utils';
import logger from '../common/core/logger';
import globalData from '../common/core/globalData';
import UIAbility from '@ohos.app.ability.UIAbility';
import imgDataSource from '../common/models/logic/imgDataSource';

export default class EntryDetailAbility extends UIAbility {
  private comicId: string;
  private remoteData: imgDataSource;

  onCreate(want) {
    try {
      globalData.abilityDetailContext = this.context;
      this.comicId = want?.parameters?.comicId;
      this.remoteData = want?.parameters?.remoteData;
      if (!utils.isEmpty(this.comicId))
        globalData.comicId = Number.parseFloat(this.comicId);
    } catch (e) {
      logger.error(e);
    }
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    try {
      utils.setLayoutFullScreen(windowStage, utils.COLOR_WHITE, utils.COLOR_BLACK, '#f7f7f7', utils.COLOR_BLACK);
      if (!utils.isEmpty(this.comicId))
        windowStage.loadContent('pages/Manga');
      else {
        AppStorage.setOrCreate('remoteData', this.remoteData);
        windowStage.loadContent('pages/Share');
      }
    } catch (e) {
      logger.error(e);
    }
  }
}